import os
from flask import render_template
from flask_cors import CORS

from apps.entrance import create_app
from apps.ext import db
from apps.model.baseAdd import baseAddData
from apps.model.modelUtils import modelUtilsMigration
from setting import openDbBase
from flask_compress import Compress

env = os.environ.get("FLASK_ENV") or 'defualt'
app = create_app(env)

# 开启gzip数据压缩
compress = Compress(app)

CORS(app, supports_credentials=True)

# 初始化创建表
with app.app_context():
    # chukuApiDb()
    print(db)
    modelUtilsMigration()
    db.create_all()
    baseAddData(db)

@app.route('/')
def hello_world():
    return render_template('index.html')

dbproconfig = openDbBase()

if __name__ == '__main__':
    app.run(host="0.0.0.0",debug=True,port=dbproconfig['CHARTPORT'],threaded=True)
    # serve(app, host='0.0.0.0', port=dbproconfig['CHARTPORT'])





